package it.polito.let.jhp.form;

import java.io.Serializable;
import java.util.Set;

public class FormInput implements Serializable, FormNode {

	private static final long serialVersionUID = -215466008242707743L;

	String name;
	
	InputAggregator parent;

	public FormInput (String name, InputAggregator parent) {
		this.name = name;
		this.parent = parent;
	}

	@Override
	public void checkMandatory(Set<String> fieldSet) throws MandatoryException {
		if (!fieldSet.contains(name)) {
			throw new MandatoryException("Field "+name+" is required");
		}
	}

	@Override
	public String toString() {
		return name;
	}

	@Override
	public void visit() {
		System.err.println(name);
		
	}

	@Override
	public InputAggregator getParent() {
		return parent;
	}

}
